package com.example.loginstructuredemo.utils;

import android.content.Context;
import android.content.SharedPreferences;


public class SPUtils {
	private static SharedPreferences sharedPreferences=null;
	
	/**
	 * 存放token的方法
	 * @param token 
	 * @param context
	 */
	public static void setToken(String token, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("token", token).commit();
		
	}
	/**
	 * 获取token的方法
	 * @param context
	 * @return
	 */
	public static String getToken(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("token", "0");
	}
	/**
	 * 存放id的方法
	 * @param
	 * @param context
	 */
	public static void setId(String id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("id", id).commit();
		
	}

	public static void setPhone(Context context, String phoneNum) {
		sharedPreferences = context.getSharedPreferences("login_info", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("phone_num", phoneNum).commit();
	}
	public static String getPhoneNum(Context context) {
		sharedPreferences = context.getSharedPreferences("login_info", Context.MODE_PRIVATE);
		return sharedPreferences.getString("phone_num", "");
	}


	/**
	 * 获取id的方法
	 * @param context
	 * @return
	 */
	public static String getId(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("id", "-1");
	}
	
	/**
	 * 存放是否第一次接诊的方法
	 * @param
	 * @param context
	 */
	public static void setOutin(String id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("av", id).commit();

	}
	/**
	 * 获取是否第一次接诊的方法
	 * @param context
	 * @return
	 */
	public static String getOutin(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("av", "0");
	}
	/**
	 * 存放手机号
	 * @param
	 * @param context
	 */
	public static void setUserName(String id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("user", id).commit();

	}
	/**
	 * 获取手机号
	 * @param context
	 * @return
	 */
	public static String getUserName(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("user", "");
	}
	/**
	 * 存放密码
	 * @param
	 * @param context
	 */
	public static void setPassword(String id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("psd", id).commit();
		
	}
	/**
	 * 获取密码
	 * @param context
	 * @return
	 */
	public static String getPassword(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("psd", "");
	}
	/**
	 * 存放是否接受极光
	 */
	public static void setJPush(Boolean id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putBoolean("push", id).commit();
		
	}
	/**
	 * 获取否接受极光
	 */
	public static Boolean getJPush(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("push", true);
	}
	/**
	 * 存放是否接受极光声音和振动
	 */
	public static void setSoundandShake(Boolean id, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putBoolean ("ss", id).commit();
		
	}
	/**
	 * 获取否接受极光声音和振动
	 */
	public static Boolean getSoundandShake(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("ss", true);
	}
	/**
	 * 是否有更新
	 * @param context 上下文
	 * @param b true表示有更新
	 */
	public static void setUpdate(Context context, boolean b){
		sharedPreferences = context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putBoolean("isUpdate", b).commit();
	}
	
	public static boolean isUpdate(Context context){
		sharedPreferences = context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("isUpdate", false);
	}
	/**
	 * 存放姓名
	 */
	public static void setRealName(String name, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("name", name).commit();
		
	}
	/**
	 * 获取姓名
	 */
	public static String getRealName(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("name", "");
	}
	/**
	 * 存放是否是领导
	 */
	public static void setLeader(String name, Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString  ("leader", name).commit();
		
	}
	/**
	 * 获取是否是领导
	 */
	public static String getLeader(Context context){
		sharedPreferences=context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("leader", "");
	}

	public static boolean isLogin(Context context) {
		sharedPreferences = context.getSharedPreferences("is_logined", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("is_logined", false);
	}

	public static void putIsLogin(boolean isLogin, Context context) {
		sharedPreferences = context.getSharedPreferences("is_logined", Context.MODE_PRIVATE);
		sharedPreferences.edit().putBoolean("is_logined", isLogin).apply();
	}

	/**
	 * 存储用户设置
	 * @param context 上下文
	 * @return 返回创建好文件的sp对象
     */
	public static SharedPreferences userSetting(Context context) {
		return context.getSharedPreferences("user_setting", Context.MODE_PRIVATE);
	}

	public static String getUserGender(Context context) {
		return userSetting(context).getString("user_sex", "男");
	}

	public static void setUserGender(Context context, String gender) {
		userSetting(context).edit().putString("user_sex", gender).apply();
	}

	public static String getUserDepartment(Context context) {
		return userSetting(context).getString("user_dept", "");
	}

	public static void setUserDepartment(Context context, String department) {
		userSetting(context).edit().putString("user_dept", department).apply();
	}
	public static String getUserJobLevel(Context context) {
		return userSetting(context).getString("user_job_level", "");
	}

	public static void setUserJobLevel(Context context, String jobLevel) {
		userSetting(context).edit().putString("user_job_level", jobLevel).apply();
	}

	public static String getUserHospital(Context context) {
		return userSetting(context).getString("user_hospital", "");
	}

	public static void setUserHospital(Context context, String hospital) {
		userSetting(context).edit().putString("user_hospital", hospital).apply();
	}


	public static String getUserTags(Context context) {
		return userSetting(context).getString("user_tags", "");
	}

	public static void setUserTags(Context context, String userTags) {
		userSetting(context).edit().putString("user_tags", userTags).apply();
	}
	public static String getUserGoodAt(Context context) {
		return userSetting(context).getString("user_good_at", "");
	}

	public static void setUserGoodAt(Context context, String goodAt) {
		userSetting(context).edit().putString("user_good_at", goodAt).apply();
	}
	public static String getUserDesc(Context context) {
		return userSetting(context).getString("user_desc", "");
	}

	public static void setUserDesc(Context context, String desc) {
		userSetting(context).edit().putString("user_desc", desc).apply();
	}
	public static String getUserPrice(Context context) {
		return userSetting(context).getString("user_price", "");
	}

	public static void setUserPrice(Context context, String price) {
		userSetting(context).edit().putString("user_price", price).apply();
	}
	public static String getUserHeader(Context context) {
		return userSetting(context).getString("user_header", "");
	}

	public static void setUserHeader(Context context, String header) {
		userSetting(context).edit().putString("user_header", header).apply();
	}


	public static String getUserType(Context context) {
		sharedPreferences = context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		return sharedPreferences.getString("Type", "");
	}

	public static void setUserType(String type, Context context) {
		sharedPreferences = context.getSharedPreferences("tokenflag", Context.MODE_PRIVATE);
		sharedPreferences.edit().putString("Type", type).apply();
	}

//	public static final void putString(String key, String value) {
//		SharedPreferences sp = YYDYApplication.getContext().getSharedPreferences("common", Context.MODE_PRIVATE);
//		sp.edit().putString(key, value).commit();
//	}
//
//	public static final String getString(String key, String defValue) {
//		SharedPreferences sp = YYDYApplication.getContext().getSharedPreferences("common", Context.MODE_PRIVATE);
//		return sp.getString(key, defValue);
//	}

}
